*This File Creates panel_all_women.dta
************************************************************
*Look at 0.Read Me for details about the merging process
*Download CFS (2016) replication files. 
*run panel_all_women.do >creates panel_all_women.dta
*then run Turnout_District_Level.do > creates collapsed data. 
************************************************************

cd "YOUR DIRECTORY HERE"

*the Storting datasets which contain information on women's turnout are at the district level. Cox, Fiva, Smith's panel_all that we merge with contains eligibility overall at the municipal level and total votes at the municipality level. 

foreach year in 1909 1912 1915 1918 { 

di "`year'" 
use "CFS/Storting`year'.dta", clear 


browse if valgkrets==.
drop if valgkrets==. 

gen hadsecondround=1 if castedvotes2overall!=0 & castedvotes2overall!=.
recode hadsecond (.=0) 
gen round=1

*We only want to keep the information related to women as they are at the district level. 


gen eligible1men=eligible1overall-eligible1women  
gen eligible2men=eligible2overall-eligible2women

gen castedvotes1men=castedvotes1overall-castedvotes1women 
gen castedvotes2men=castedvotes2overall-castedvotes2women 


*FINAL ROUND is either round1 if there was no second round, or round2 if there was a second round. 
foreach group in men women overall {

gen eligible`group'_final_pre=eligible1`group' if hadsecond==0
replace eligible`group'_final_pre=eligible2`group' if hadsecond==1

gen casted`group'_final_pre=castedvotes1`group' if hadsecond==0
replace casted`group'_final_pre=castedvotes2`group' if hadsecond==1

gen turnout`group'_final_pre=casted`group'_final/eligible`group'_final

la var casted`group'_final_pre "`group' final round ballots cast, pre-reform" 
la var eligible`group'_final_pre "`group' final round eligibility, pre-reform" 
la var turnout`group'_final_pre "`group' final round turnout, pre-reform" 

}

gen approved_final_pre=approvedvotes1 if hadsecond==0
replace approved_final_pre=approvedvotes2 if hadsecond==1



*keep round hadsecond valgkrets year turnout* approved_* castedmen castedwomen castedoverall eligiblemen eligiblewomen eligibleoverall
  
 if year==1909 { 
merge 1:m valgkrets round year using "panel_all.dta" , gen(_mladies`year') 
save "panel_all_women.dta", replace
}
else {
merge 1:m valgkrets round year using "panel_all_women.dta" , gen(_mladies`year') 
save "panel_all_women.dta", replace
}
}


 
 
*1909 *662 observations matched. 
*1912 *673 matched
*1915 *693 matched
*1918 708 matched
